package com.ansion.baseui.base.view;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;

import androidx.annotation.Nullable;

/**
 * Description :
 * FontSize : 14
 * LineSpacing : 0dp
 * FontWeight : 400 (Regular)
 */
public class ParagraphTextView extends androidx.appcompat.widget.AppCompatTextView {

    private final float mFontSize = 14f;
    private final float mLineSpacing = 0f;
    private final int mFontWeight = 400;

    public ParagraphTextView(Context context) {
        this(context, null);
    }

    public ParagraphTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ParagraphTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(attrs);
    }

    public void init(@Nullable AttributeSet attrs) {
        setTextSize(mFontSize);
        setLineSpacing(mLineSpacing, 1.0f);

        try {
            Typeface typeface;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
                typeface = Typeface.create(null, mFontWeight, false);
            } else {
                typeface = Typeface.defaultFromStyle(Typeface.NORMAL);
            }
            setTypeface(typeface);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }

    public void updateLineSpacing(float mult) {
        setLineSpacing(mLineSpacing, mult);
    }
}
